<template>
  <view class="content">
    <view class="user_top">
      <image class="head_img" :src="userInfo.headimgurl"></image>
      <view class="user_num">
        <view class="user_name">{{userInfo.real_name}}</view>
        <view>卡号：{{userInfo.card_num}}</view>
      </view>
      <view class="user_level">{{userInfo.card_level}}</view>
    </view>
    <view class="menu_box">
      <view class="menu_title">
        <view class="title_item">
          <text class="iconfont icon_size2 iconyue"></text>余额 {{userInfo.balance}}
        </view>
        <view class="title_item">
          <text class="iconfont icon_size1 iconjifen1"></text>积分 {{userInfo.point}}
        </view>
      </view>
      <view class="menu_list">
        <view class="menu_item" v-for="(item,index) in menuData" :key="index" @tap="goto(item.path)">
          <view :class=item.icon></view>
          <view class="item_name">{{item.name}}</view>
        </view>
      </view>
    </view>
    <AtToast :isOpened="market.isShow" :text="market.text" icon="close"></AtToast>
    <user-point v-if="showPoint" :point="pagePoint" :type="pageType" :uid="pageUid" @close="closePoint"></user-point>
  </view>
</template>

<script>
import './menuIndex.scss';
import Taro from '@tarojs/taro';
import UserAPI from "../../api/user.js"
// import { getUrlArgObject } from '../../utils/spliturl'
import UserPoint from './userPoint.vue'
export default {
  data(){
    return{
      mobile: "",
      market: {
        isShow: false,
        text: "",
      },
      userInfo: {},
      menuData: [
        { path: "choseUserWx", icon: "iconfont icon_size iconchuzhi bg_y", name: "立即充值"},
        { path: "android", icon: "iconfont icon_size icongouwuche1 bg_r", name: "消费扣款"},
        { path: "point1", icon: "iconfont icon_size iconjifen1 bg_b", name: "积分累加"},
        { path: "point2", icon: "iconfont icon_size iconjifen1 bg_g", name: "积分核减"},
      ],
      showPoint: false,
      pagePoint: "",
      pageType: "1",
      pageUid: "",
    }
  },
  components: {
    UserPoint
  },
  mounted(){
    console.log('create===========')
    this.userInfo = Taro.getStorageSync('userInfor')
    this.getUserInfor();
  },
  methods: {
    getUserInfor(){
      var data = {
        token: Taro.getStorageSync('token'),
        app_id: Taro.getStorageSync('app_id'),
        page: 1,
        point_order: 0,
        mobile: this.userInfo.mobile
      };
      UserAPI.getUserList(data).then(res => {
        if (res.code == 200) {
          if (res.data.result.length > 0) {
            this.userInfo = res.data.result[0];
            Taro.setStorageSync('userInfor', this.userInfo);
          }
        }
      })
    },
    goto(path){
      if(path == 'android'){
        console.log('跳安卓')
      }else if(path == "choseUserWx"){
        path = "/pages/recharge/choseUserWx?mobile=" + this.userInfo.mobile
        Taro.navigateTo({ url: path });
      }else if(path == "point1"){
        // path = "userPoint?uid=" + this.userInfo.uid + "&type=1&point=" +this.userInfo.point
        // Taro.navigateTo({ url: path });
        this.pageUid = this.userInfo.uid;
        this.pageType = "1";
        this.pagePoint = this.userInfo.point;
        this.showPoint = true;
      }else if(path == "point2"){
        // path = "userPoint?uid=" + this.userInfo.uid + "&type=2&point=" +this.userInfo.point
        // Taro.navigateTo({ url: path });
        this.pageUid = this.userInfo.uid;
        this.pageType = "2";
        this.pagePoint = this.userInfo.point;
        this.showPoint = true;
      }
    },
    closePoint(i){
      this.showPoint = false;
      if(i == 1){
        this.getUserInfor();
      }
    }
  }
}

</script>
